Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not include defaults in models #4

Merged
merged 3 commits into from
May 7, 2020
Merged

Do not include defaults in models #4

merged 3 commits into from
May 7, 2020

Conversation

tiangolo
Copy link
Owner

@tiangolo tiangolo commented May 7, 2020

🐛 Do not include defaults from SQLAlchemy models in Pydantic models.

SQLAlchemy defaults are supposed to be generated at insertion/update time, not generated by the Pydantic model before creating a new object/record.

It's also currently broken, as the default included is a SQLAlchemy object, not an actual default.

@codecov
Copy link

codecov bot commented May 7, 2020

Codecov Report

Merging #4 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master        #4   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines           90       109   +19     
=========================================
+ Hits            90       109   +19     
Impacted Files Coverage Δ
pydantic_sqlalchemy/main.py 100.00% <100.00%> (ø)
tests/test_pydantic_sqlalchemy.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e651a6a...4eec8de. Read the comment docs.

@tiangolo tiangolo merged commit 205e59c into master May 7, 2020
@tiangolo tiangolo deleted the no-defaults branch May 7, 2020 16:03
@shawnwall
Copy link

Sorry to bring it up on this old case, but... what about server_default in contrast to default which you are covering? I'm currently trying to get a project going with fastapi/pydantic/sqlalchemy, and am a bit hung up on how to define schemas for base/create/update/etc "perfectly" when i have sqlalchemy models with server defaults.

@tiangolo
Copy link
Owner Author

tiangolo commented Nov 5, 2022

Humm, I'm actually not sure what would be the best way to handle server/DB defaults, I think I haven't used them much myself.

Also, you might want to check SQLModel: https://sqlmodel.tiangolo.com/

Sorry for the long delay! 🙈 I wanted to personally address each issue/PR and they piled up through time, but now I'm checking each one in order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants